package com.hhh.petadopt.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.hhh.petadopt.pojo.Adopt;
import com.hhh.petadopt.pojo.Pet;
import com.hhh.petadopt.service.AdoptService;
import com.hhh.petadopt.utils.JsonUtils;

/**
 * 收养列表
 * @author 杜镇声声
 *
 */
@Controller
public class AdoptController {
	@Autowired
	private AdoptService adoptService;
	
	//展示收养列表
	@RequestMapping(value="/adopt/adoptList")
	public String showAdoptList(Model model) {
		//执行查询
		List<Pet> petList = adoptService.selectPetLimit();
		//将数据保存到模型中
		model.addAttribute("petList", petList);
		return "adoptlist";
	}
	
	//展示收养详情
	@RequestMapping(value="/adopt/petInfo")
	public String showPetInfo(Long id,Model model) {
		Pet petInfo = adoptService.selectPetById(id);
		//将数据保存到模型中
		model.addAttribute("petInfo", petInfo);
		return "petInfo";
	}
	
	//请求信息入库
	@RequestMapping(value="/adopt/saveAdopt")
	@ResponseBody
	public String saveAdopt(Adopt ap) {
		//执行操作
		adoptService.saveAdoptPet(ap);
		return JsonUtils.objectToJson(ap);
	}

}
